/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
//
// Extend the XmlTreeLoader to set some custom TreeNode attributes specific to our application:
//
Ext.app.BookLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
    processAttributes : function(attr){
        if (attr.first) { // is it an author node?
			// Set the node text that will show in the tree since our raw data does not include a text attribute:
			attr.text = attr.first + ' ' + attr.last;
		// Author icon, using the gender flag to choose a specific icon:
		//attr.iconCls = 'author-' + attr.gender;
		
		// Override these values for our folder nodes because we are loading all data at once.  If we were
		// loading each node asynchronously (the default) we would not want to do this:
		//attr.loaded = true;
		//attr.expanded = true;
		}
		else if (attr.dn) {
			attr.text = attr.dn;
			//if (attr.isleaf) {
			//    attr.leaf = true;
			//} else {
			//	attr.loaded = true;
		    //    attr.expanded = true;
			//}
		} else if (attr.titlex) {
			attr.text = attr.titlex;
			//if (attr.isleaf) {
			//    attr.leaf = true;
			//}
			//attr.loaded = true;
			//attr.expanded = true;
		} else if (attr.dnx) {
			attr.text = attr.dnx;
			//if (attr.isleaf) {
			//    attr.leaf = true;
			//}
			//attr.loaded = true;
		}
        //else if(attr.namex){ // is it a book node?
	console.log(attr.tagName);
        if(attr.first){ // is it an author node?
            //attr.iconCls = 'book';
            //attr.iconCls = 'book';
            attr.iconCls = 'author-m';
            
            // Tell the tree this is a leaf node.  This could also be passed as an attribute in the original XML,
            // but this example demonstrates that you can control this even when you cannot dictate the format of 
            // the incoming source XML:
            //attr.leaf = true;
        //}
            //attr.leaf = true;
            //attr.loaded = true;
        } else {
        	attr.text = attr.tagName;
        	//attr.loaded = true;
        }
        attr.loaded = true;
    }
});

Ext.onReady(function(){
    var tree = new Ext.tree.ColumnTree({
        width: 550,
        height: 300,
        rootVisible:true,
        autoScroll:true,
        title: 'Example Tasks',
        renderTo: Ext.getBody(),
        
        columns:[{
            header:'Task',
            width:330,
            dataIndex:'task'
        },{
            header:'Duration',
            width:100,
            dataIndex:'duration'
        },{
            header:'Assigned To',
            width:100,
            dataIndex:'user'
        }],
 
        //loader: new Ext.tree.TreeLoader({
        //    dataUrl:'column-data.json',
        //    uiProviders:{
        //        'col': Ext.tree.ColumnNodeUI
        //    }
        //}),
       // Our custom TreeLoader:
        loader: new Ext.app.BookLoader({
            dataUrl:'http://127.0.0.1:9998/jersey/xpathsearch/xmltest',
            uiProviders:{
                'col': Ext.tree.ColumnNodeUI
            }
        }),
 
        root: new Ext.tree.AsyncTreeNode({
            text:'Tasks'
        })
    });
});
